#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //创建菜单栏
    QMenuBar *menu_bar=new QMenuBar();
    //将菜单栏添加到窗口中
    this->setMenuBar(menu_bar);
    //构造菜单元素
    QMenu *menu1=new QMenu("菜单1");
    QMenu *menu2=new QMenu("菜单2");
    //将菜单1和菜单2元素添加到菜单栏中
    menu_bar->addMenu(menu1);
    menu_bar->addMenu(menu2);

    //构建子菜单对象
    QMenu *child_menu=new QMenu("子菜单");
    //构建菜单项
    QAction *action1=new QAction("菜单项1");
    QAction *action2=new QAction("菜单项2");
    QAction *action3=new QAction("菜单项3");
    //将子菜单和菜单项添加到菜单1中
    menu1->addMenu(child_menu);
    menu1->addAction(action1);
    menu1->addAction(action2);
    menu1->addAction(action3);

    //构造子菜单项
    QAction *action4=new QAction("子菜单项1");
    QAction *action5=new QAction("子菜单项2");
    QAction *action6=new QAction("子菜单项3");
    //将子菜单项添加到子菜单中
    child_menu->addAction(action4);
    child_menu->addAction(action5);
    child_menu->addAction(action6);
}

MainWindow::~MainWindow()
{
    delete ui;
}

